package com.hu.jie.mywallpager.apadter;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.hu.jie.mywallpager.R;
import com.hu.jie.mywallpager.bean.JsonList;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
 * Created by jie on 2016/7/8.
 */
public class SeekAdapter extends BaseAdapter {
    private Context mContext;
    private List<JsonList.FirstInnerBean> mDatas;
    private DisplayImageOptions mOptions;

    public SeekAdapter(Context context, List<JsonList.FirstInnerBean> datas) {
        this.mContext = context;
        this.mDatas = datas;
        mOptions = new DisplayImageOptions.Builder()
                .showImageOnFail(R.mipmap.ic_launcher)
                .showImageOnLoading(R.mipmap.ic_launcher)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .cacheOnDisk(true)
                .cacheInMemory(true)
                .build();
    }

    @Override
    public int getCount() {
        return mDatas == null ? 0 : mDatas.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_search_bottom, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        JsonList.FirstInnerBean bean = mDatas.get(position);
        holder.tv_title.setText(bean.keyword);
        ImageLoader.getInstance().displayImage(bean.imgs.get(0),holder.iv1,mOptions);
        ImageLoader.getInstance().displayImage(bean.imgs.get(1),holder.iv2,mOptions);
        ImageLoader.getInstance().displayImage(bean.imgs.get(2),holder.iv3,mOptions);

        return convertView;
    }

    private class ViewHolder {
        private TextView tv_title;
        private ImageView iv1, iv2, iv3;

        public ViewHolder(View itemView) {
            tv_title = (TextView) itemView.findViewById(R.id.bottom_tv_title);
            iv1 = (ImageView) itemView.findViewById(R.id.iv_1);
            iv2 = (ImageView) itemView.findViewById(R.id.iv_2);
            iv3 = (ImageView) itemView.findViewById(R.id.iv_3);
        }
    }
}
